package joney.main.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;

public abstract class AbstractAction extends Action implements ISelectionListener, 
ActionFactory.IWorkbenchAction{
	
	protected final IWorkbenchWindow window;
	
	
	public AbstractAction(IWorkbenchWindow window, String name, String ID)
	{
		this.window = window;
		window.getSelectionService().addSelectionListener(this);
		
		//setActionDefinitionId(ID);
		setId(ID);
		setText(name);
	}
	
	public AbstractAction(IWorkbenchWindow window, String name, String ID, int style)
	{
		super(name, style);
		
		this.window = window;
		window.getSelectionService().addSelectionListener(this);
		
		//setActionDefinitionId(ID);
		setId(ID);
	}
	
	public void setCtrlAcceleratorKey(char key)
	{
		this.setAccelerator(SWT.CTRL | key);
	}
	
	public void dispose() {
		window.getSelectionService().removeSelectionListener(this);
	}


	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		//do nothing
	}
	
	public abstract void run();

}
